<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html lang="zh">
<head>
    <meta charset="UTF-8">
    <title>电影列表</title>
    <style>
        /* 页面背景和基础布局 */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f7fc;
            margin: 0;
            padding: 0;
        }

        header {
            background-color: #3498db;
            color: white;
            padding: 15px;
            text-align: right;
        }

        header a {
            color: white;
            font-weight: bold;
            text-decoration: none;
        }

        header a:hover {
            text-decoration: underline;
        }

        .container {
            margin: 20px;
        }

        /* 查询表单样式 */
        form {
            margin-bottom: 20px;
        }

        form label {
            font-weight: bold;
            margin-right: 10px;
        }

        form input[type="text"] {
            padding: 8px;
            font-size: 14px;
            border-radius: 4px;
            border: 1px solid #ccc;
            margin-right: 10px;
        }

        form input[type="submit"] {
            padding: 8px 16px;
            background-color: #3498db;
            color: white;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }

        form input[type="submit"]:hover {
            background-color: #2980b9;
        }

        /* 电影列表表格样式 */
        table {
            width: 100%;
            border-collapse: collapse;
            margin-top: 20px;
            background-color: white;
            box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
        }

        th, td {
            padding: 12px;
            text-align: center;
            border: 1px solid #ddd;
        }

        th {
            background-color: #3498db;
            color: white;
        }

        tr:nth-child(even) {
            background-color: #f9f9f9;
        }

        tr:hover {
            background-color: #f1f1f1;
        }

        .highlight {
            background-color: yellow;
        }

        /* 操作链接样式 */
        a {
            color: #3498db;
            text-decoration: none;
        }

        a:hover {
            text-decoration: underline;
        }

        /* 提示信息 */
        .no-movies {
            text-align: center;
            font-size: 18px;
            color: #777;
        }
    </style>
</head>
<body>

<header>
    <!-- 显示当前登录的用户名 -->
    <c:if test="${not empty user}">
        <span>欢迎, ${user}！</span> |
        <a href="logout">退出登录</a>
    </c:if>
    <c:if test="${empty user}">
        <a href="login.jsp">登录</a> | <a href="register.jsp">注册</a>
    </c:if>
</header>

<div class="container">
    <h1>电影列表</h1>

    <!-- 添加查询表单 -->
    <form action="movie?action=list" method="get">
        <label for="searchName">名称:</label>
        <input type="text" id="searchName" name="name" value="${param.name}"/>

        <label for="searchDirector">导演:</label>
        <input type="text" id="searchDirector" name="director" value="${param.director}"/>

        <label for="searchGenre">类型:</label>
        <input type="text" id="searchGenre" name="genre" value="${param.genre}"/>

        <input type="submit" value="查询"/>
    </form>

    <a href="movie?action=add">添加电影</a>

    <table>
        <tr>
            <th>ID</th>
            <th>名称</th>
            <th>导演</th>
            <th>类型</th>
            <th>上映日期</th>
            <th>操作</th>
        </tr>

        <!-- 检查 movieList 是否为空 -->
        <c:if test="${not empty movieList}">
            <c:forEach var="movie" items="${movieList}">
                <tr class="<c:if test='${not empty param.name and movie.name == param.name}'>highlight</c:if>
                           <c:if test='${not empty param.director and movie.director == param.director}'>highlight</c:if>
                           <c:if test='${not empty param.genre and movie.genre == param.genre}'>highlight</c:if>">
                    <td>${movie.id}</td>
                    <td>${movie.name}</td>
                    <td>${movie.director}</td>
                    <td>${movie.genre}</td>
                    <td>${movie.releaseDate}</td>
                    <td>
                        <a href="movie?action=edit&id=${movie.id}">编辑</a> |
                        <a href="movie?action=delete&id=${movie.id}" onclick="return confirm('确认删除？')">删除</a>
                    </td>
                </tr>
            </c:forEach>
        </c:if>

        <!-- 如果 movieList 为空 -->
        <c:if test="${empty movieList}">
            <tr class="no-movies">
                <td colspan="6">没有找到电影数据</td>
            </tr>
        </c:if>
    </table>
</div>

</body>
</html>
